@extends('layouts.template')

@section('title', '管理后台')

@section('content')

    <script>
        $(function(){

            var form = new Vue({
                el:'#contentpanel',
                data:{
                },
                computed:{
                },
                mounted:function(){
                },
                watch: {
                },
                methods:{
                },
                components:{
                }
            });

            $("#detail").on("hidden.bs.modal", function() {
                $(this).removeData("bs.modal");
                $(this).find('.modal-content').empty();
            });

            $("#coupon").on("show.bs.modal", function(event) {
                var button = $(event.relatedTarget);
                var modal = $(this);
                modal.find('[name=merchant_id]').val(button.data('id'));
            });

            var validator = $("#coupon-form").validate({
                rules: {
                    merchant_id:{
                        required:true,
                    },
                    coupon_id:{
                        required:true,
                    },
                    count:{
                        required:true,
                        digits:true,
                    },
                },
                messages: {
                    merchant_id:{
                        required:'缺少商家id',
                    },
                    coupon_id:{
                        required:'请选择优惠券',
                    },
                    count:{
                        required:'请输入发放数量',
                    },
                },
                submitHandler: function(form) {
                    form.submit();
                },
            });
        });

    </script>

    <div class="panel-body">
        <div class="panel panel-default">
            <div class="panel-body">
                <form action="" method="GET" class="form-inline">
                    <div>
                        {!! $filter !!}
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="contentpanel" id="contentpanel">

        <div class="row">
            <div class="col-md-12">
                <div class="table-responsive">
                    <table class="table mb30">
                        <thead>
                        <tr style="white-space:nowrap">
                            <th>注册时间</th>
                            <th>用户名</th>
                            <th>手机号</th>
                            <th>用户类型</th>
                            <th>累计下单</th>
                            <th>累计金额</th>
                            <th>积分</th>
                            <th>定价下单</th>
                            <th>优惠券</th>
                            <th>货品仓库</th>
                            <th>用户详情</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($list as $row):?>
                            <tr data-id="{{$row->me_id}}">
                                <td>{{$row->me_add_time}}</td>
                                <td>{{$row->me_username}}</td>
                                <td>{{$row->me_phone}}</td>
                                <td>{{$row->category_type}}</td>
                                <td>{{$row->me_total_orders}}</td>
                                <td>{{$row->me_total_fee}}</td>
                                <td>{{$row->me_points}}</td>
                                <td>未开通</td>
                                <td>
                                    <a href="{{url("merchant/coupon/{$row->me_id}")}}" class="btn btn-white">查看</a>
                                    <button class="btn btn-white" data-toggle="modal" data-target="#coupon" data-id="{{$row->me_id}}">发放</button>
                                </td>
                                <td><a href="{{url("merchant/goods/{$row->me_id}")}}" class="btn btn-white">查看</a></td>
                                <td><a href="{{url("ajax/merchant/detail/{$row->me_id}")}}" class="btn btn-white" data-toggle="modal" data-target="#detail">查看</a></td>
                                <td>
                                    @if ($row->disabled)
                                        <a onclick="return confirm('确定')" href="{{url("merchant/enable/{$row->me_id}")}}" class="btn btn-success">解封</a>
                                    @else
                                        <a onclick="return confirm('确定')" href="{{url("merchant/disable/{$row->me_id}")}}" class="btn btn-danger">封号</a>
                                    @endif
                                </td>
                            </tr>
                        <?php endforeach;?>
                        </tbody>
                    </table>
                </div>
                <!-- table-responsive -->
                {{ @!$list->isEmpty() ? $list->appends(request()->all())->links() : '' }}
            </div>
            <!-- col-md-12 -->
        </div>
    </div><!-- contentpanel -->

    <div class="modal fade" id="detail" tabindex="-1" role="dialog" data-keyboard="false">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            </div>
        </div>
    </div>

    <div class="modal fade" id="coupon" tabindex="-1" role="dialog" data-keyboard="false">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">发放优惠券</h4>
                </div>
                <form id="coupon-form" method="post" action="{{url("coupon/assign")}}">
                    {{csrf_field()}}
                    <input type="hidden" name="merchant_id">
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">选择优惠券</label>
                            <div class="col-sm-8">
                                <select class="width300 select-search-hide" name="coupon_id">
                                    <option value="">请选择</option>
                                    @foreach ($coupon_list as $coupon_id=>$coupon_name)
                                    <option value="{{$coupon_id}}">{{$coupon_name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">发放数量（张）</label>
                            <div class="col-sm-3">
                                <input type="text" placeholder="请输入发放数量" class="form-control" name="count">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">确定发放</button>
                    </div>
                </form>
            </div>
        </div>
    </div>


@endsection

